<?php
namespace Admin\Controller;

class FeedbackController extends AdminController
{

    public function index()
    {
        $feedback = M("feedback");
        
        Cookie('__forward__', $_SERVER['REQUEST_URI']);
        
        $map = array();
        if (I('is_read')) {
            $map = array(
                'is_read' => 1
            );
        }
        
        $count = $feedback->where($map)->count();
        // 查询满足要求的总记录数
        $Page = new \Think\Page($count, 10);
        // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show(); // 分页显示输出
        
        $this->assign('_page', $show); // 赋值分页输出
        
        $list = $feedback->where()
            ->order('id desc')
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        int_to_string($list,array('is_read'=>array(0=>'未读',1=>'已读')));
        
        $member=M('member');
        foreach($list as &$key){
            $key['nickname']=$member->where(array('uid'=>$key['uid']))->getField('nickname');
        }
        
        $this->assign('flist', $list);
        $this->display();
    }
    
    public function detail(){
        if(IS_POST){
            $this->success('跳转',Cookie('__forward__'),0);
        }else{
        $id=I('id');
        $m=M('feedback');
        if($id){
            $m->where(array('id'=>$id))->setField('is_read',1);
            $info=$m->where(array('id'=>$id))->find();
            
            if($info['uid']){
                $member=M('member'); 
                $info['nickname']=$member->where(array('uid'=>$info['uid']))->getField('nickname');
            }            
            $this->assign('info',$info);
            $this->display();
    
        }
        }
    }
    public function del(){
        $id=I('id');
        $m=M('feedback');
        if($id){
            $m->where(array('id'=>$id))->delete();
          if($m){
              $this->success('删除成功');
          }else{
              $this->error('删除失败');
          }
    
        }
    }
    
}